package com.zcxy360.sandtable.controller;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zcxy360.sandtable.domain.CourseStage;
import com.zcxy360.sandtable.service.CourseStageService;

/**
 * 课程阶段接口
 * @author 盛亚辉
 *
 */
@RequestMapping("course/stage")
@RestController
public class CourseStageController {
	
	@Autowired
	private CourseStageService courseStageService;
	
	/**
	 * 获取阶段
	 * @param stageId 阶段id
	 * @return 阶段对象
	 */
	@RequiresAuthentication
	@GetMapping("{stageId}")
	public Object getByStageId(@PathVariable("stageId") Integer stageId) {
		return courseStageService.getByStageId(stageId);
	}
	
	/**
	 * 获取阶段集合
	 * @param courseId 课程id
	 * @return 阶段集合
	 */
	@RequiresAuthentication
	@GetMapping
	public Object listByCourseId(@RequestParam("courseId") Integer courseId) {
		return courseStageService.listByCourseId(courseId);
	}
	
	/**
	 * 更新阶段
	 * @param courseStage 阶段字段
	 * @return 布尔值
	 */
	@RequiresRoles("teacher")
	@PutMapping
	public Object update(CourseStage courseStage) {
		return courseStageService.update(courseStage);
	}
	
	/**
	 * 开启小组阶段
	 * @param courseId 课程id
	 * @param keep 是否保持学生进度不变
	 * @return 布尔值
	 */
	@RequiresRoles("teacher")
	@PutMapping("startTeamStage")
	public Object startInfer(Integer courseId,boolean keep) {
		return courseStageService.startTeamStage(courseId,keep);
	}
	
}
